package org.example.service.impl;

import jakarta.annotation.Resource;
import org.example.entity.Order;
import org.example.feign.AccountFeign;
import org.example.mapper.OrderMapper;
import org.example.service.OrderService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class OrderServiceImpl implements OrderService {
    @Resource
    private OrderMapper orderMapper;
    @Resource
    private AccountFeign accountFeign;
    @Transactional
    @Override
    public Order create(String userId, String commodityCode, int orderCount) {

//        int orderMoney = calculate(commodityCode, orderCount);
        int orderMoney = 100;
        //减钱
        accountFeign.debit(userId, -orderMoney);
        Order order = new Order(null, userId, commodityCode, orderCount, orderMoney);

        // INSERT INTO orders ...
        int insert = orderMapper.insert(order);
        int a = 1/0;
        return  order;
    }
}
